package cn.cyh.service.impl;

import cn.cyh.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * Created by Charlie on 2018/7/13.
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void create(String useName, Integer age){
        jdbcTemplate.update("INSERT INTO USER(NAME, AGE) VALUE (?, ?)", useName, age);
    }

    @Override
    public void deleteByName(String userName){
        jdbcTemplate.update("delete from USER where NAME = ?", userName);
    }

    @Override
    public Integer getAllUsers(){
        return jdbcTemplate.queryForObject("SELECT COUNT(1) FROM USER", Integer.class);
    }

    @Override
    public void deleteAllUsers(){
        jdbcTemplate.update("delete from USER");
    }
}
